<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="org.limp.mine.DateTrimmer"%>
<%@ page import="org.limp.mine.StringTool"%>
<%@ page import="org.limp.mine.RandomUtil"%>
<%@ page import="jt.classic.system.wordbook.XWordbook"%>
<%@ page import="jt.classic.system.ISystem"%>
<%@ page import="jt.classic.system.user.IUser"%>
<%@ page import="java.util.List"%>
<%@ page import="jt.classic.app.info.AInfoDirectory"%>
<%
	String context = jt.classic.system.ISystem.getContextPath();

	IUser user = ISystem.getSessionUser(request);

	List list = (List) request.getAttribute("list");

	String listtype = (String) request.getAttribute("listtype");

	AInfoDirectory direc = (AInfoDirectory) request
			.getAttribute("direc");
	
	String uniqueid = RandomUtil.getRandomString(10);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>信息发布</title>
</head>
<jsp:include page="../head.jsp"></jsp:include>
<link rel="stylesheet" type="text/css"
	href="<%=context%>/app/info/css/directree.css" />
<script type="text/javascript" src="<%=context%>/app/info/js/myjs.js"></script>
<script type="text/javascript"
	src="<%=context%>/app/info/js/lanmuselect.js"></script>
<link rel="stylesheet" type="text/css"
	href="<%=context%>/system/group/css/groupmanage.css" />
<script type="text/javascript"
	src="<%=context%>/system/group/js/groupselect.js"></script>
<script>
   function handleSelect1(){
      <%if(direc != null){%>setLanmuPath('<%=direc.iextpath()%>');<%}%>
      selectlanmu('idid', 'idname');
   }
   
   function handleSelect2(){
      selectGroupOnly('isareaid', 'isareaname');
   }
   
   function handleSend(){
       var rnt = false;
       if(isblank(document.form1.iftitle)){
          alert("请填写标题");
       }else if(isblank(document.form1.idid)){
          alert("请选择信息所属栏目");
       }else if(confirm("确定提交")){
          var it = document.form1.itid;
          if(it){
             createHidden("itname",it.options[it.selectedIndex].text);
          }
          
          if(!isblank(document.form1.isareaid)){
             var ids = document.form1.isareaid.value.split(",");
             var names = document.form1.isareaname.value.split(",");
             var countIssue = "";
             if(ids != ""){
	             for(var i=0;i<ids.length;i++){
	                 createHidden("isotype_" + i,"info");
	                 createHidden("isareaid_" + i,ids[i]);
	                 createHidden("isareaname_" + i,names[i]);
	                 createHidden("isastime_" + i,"");
	                 createHidden("isaestime_" + i,"");
	                 if(i == ids.length - 1){
	                    countIssue += i;
	                 }else{
	                    countIssue += i + ",";
	                 }
	             }
             }else{
                 countIssue = "0";
                 createHidden("isotype_0","info");
	             createHidden("isareaid_0","0");
	             createHidden("isareaname_0","");
	             createHidden("isastime_0","");
	             createHidden("isaestime_0","");
             }
             
             createHidden("countIssue",countIssue);
          }
          
          rnt = true;
       }
       
       return rnt;
   }
   
   function handleSP(){
       if(handleSend()){
	       document.form1.target = "_self";
	       document.form1.action = context + "/app/info.do?method=saveinfo&listtype=<%=listtype%>&sp=infoshenpi";
	       document.form1.submit();
       }
   }
   
   var submitAction = false;
   
   function handleSumbit(){
       if(handleSend()){
            Ext.MessageBox.wait('提交保存过程中...');   
		    Ext.Ajax.request({       
		        //请求地址       
		       url: context + "/app/info.do?method=saveinfo&uniqueid=<%=uniqueid%>",       
		       //提交参数组       
		       fileUpload: true,   
		       form: 'form1',   
		       scope: 'form1',     
		       //成功时回调       
		       success: function(response, options) {       
		           //获取响应的json字符串        
		           Ext.MessageBox.hide();
		           
		           var json = response.responseText;    
                   var o = Ext.util.JSON.decode(json);
		           
		           if (o.success) {
                       /*
                       Ext.Msg.alert('提示', '提交保存成功！'); 
                       window.document.form1.reset();
                       getFrameDocument('FCKeditor1___Frame').FCKUndo.SaveUndoStep();
					   getFrameDocument('FCKeditor1___Frame').FCK.SetHTML('');
					   getFrameDocument('FCKeditor1___Frame').FCKUndo.Typing = true;
					   */
					   alert("提交保存成功！");
					   submitAction = true;
					   handleRefresh();
                   }else{
		               Ext.Msg.alert('提示', '提交保存失败！'); 
		           }                
		       }      
		     }); 
       }
   }
   
   /**
    * 不保存内容信息时清理内容资源
    */
   function cleanInfoResources(){
       if(!submitAction){
	       Ext.Ajax.request({       
		        //请求地址       
		       url: context + "/app/info.do?method=cleanresources",       
		       params : {
		           uniqueid : '<%=uniqueid%>'
		       }
		    });
	   }
   }
   
   function init(){
       /* 调整父窗口frame高度 */
		if (parent.resizeFrame) {
			parent.resizeFrame(document.getElementsByTagName("body")[0].scrollHeight + 50);
		}
   }
</script>
<style>
  form#form1 label {
	clear:left;
	display:block;
	float:left;
	width:100px;
	text-align:right;
	padding-right:10px;
	margin-bottom:5px;
}
</style>
<body onload="javascript:init();" onbeforeunload="javascript:cleanInfoResources();">
<OBJECT id=dlgHelper
	CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" width="0px"
	height="0px"></OBJECT>
<form id="form1" name="form1" method="post"
	enctype="multipart/form-data" action="">
	<input type="hidden" name="ifuserid" value="<%=user.ilogid()%>"> 
	<input type="hidden" name="ifusername" value="<%=user.iname()%>"> 
	<input type="hidden" name="ifgroupid" value="<%=user.igroup().id()%>">
    <input type="hidden" name="ifgroupname" value="<%=user.igroup().iname()%>"> 
    <input type="hidden" name="ifdate" value="<%=DateTrimmer.getYMDHMS()%>"> 
    <span id="panel"></span>
<div style="margin-top:15px;margin-left:15px;">
<input type="button" value="提交" onclick="javascript:handleSumbit();"> 
<input type="reset" value="重新填写">
<input type="reset" value="返回" onclick="javascript:window.history.back(-1);">
</div>
<fieldset id="lanmu" style="margin-left:15px;width:90%;"><legend>信息发布 - 新建信息</legend> <label
	for="iftitle">标题</label> <input type="text" id="iftitle" name="iftitle"
	style="width:550px;" />&nbsp;<img src="<%=context %>/app/info/images/theme.png" style="cursor:hand;" onclick="javascript:showPanel('');" title="设计"/><input type="hidden"
	id="iffont" name="iffont" value="宋体"> <input type="hidden"
	id="ifcolor" name="ifcolor" value="#000000"> <input
	type="hidden" id="ifsize" name="ifsize" value="6pt"> <br />
<label for="ifprovide">信息来源</label> <input type="text"
	style="width:550px;" id="ifprovide" name="ifprovide" /> <br />
<%
if (listtype.indexOf("type") > -1) {
%> <label for="itid">类别</label> <select id="itid" name="itid">
	<%
				if (list != null && !list.isEmpty()) {
				for (int i = 0; i < list.size(); i++) {
			XWordbook wb = (XWordbook) list.get(i);
	%>
	<option value="<%=wb.getID()%>"><%=wb.getName()%></option>
	<%
			}
			}
	%>
</select><br />
<%
}
%> <%
 if (listtype.indexOf("directory") > -1) {
 %> <label>所属栏目</label> <input type="text" style="width:550px;"
	id="idname" name="idname" readonly
	value="<%=(direc != null ? direc.iextpathtext() : "") %>" />&nbsp;<img src="<%=context %>/app/info/images/theme.png" style="cursor:hand;" onclick="javascript:handleSelect1();" title="选择"/>
<input type="hidden" id="idid" name="idid"
	value="<%=(direc != null ? direc.id() : "") %>" /> <br />
<%
}
%> <label>发布范围</label> <input type="text" readonly id="isareaname"
	name="isareaname" value="临时组" style="width:550px;" />&nbsp;<img src="<%=context %>/app/info/images/theme.png" style="cursor:hand;" onclick="javascript:handleSelect2();" title="选择"/>
<input type="hidden" id="isareaid" name="isareaid" value="temp" /> <input
	type="hidden" id="gtemp" name="gtemp" value="gtemp" /> <br />
<label>发布人</label> <b><%=user.iname()%></b> <br />
<label>所在部门</label> <b><%=(user.igroup() != null) ? user.igroup().iflumelabel(
					null) : ""%></b> <br />
<label
	for="iftop">置顶顺序</label> <input type="text" id="iftop" name="iftop"
	style="width:550px;" value="0"/><br />					
<label for="ifreceipt0">开放评论</label>  <input id="ifreceipt0"
	name="ifreceipt" type="radio" value="1" /> 是 <input id="ifreceipt1"
	name="ifreceipt" checked="checked" type="radio" value="0" /> 否 <br />
<label for="allfree">添加附件</label> <input type="file" id="allfree"
	style="width:550px;" name="ALLFREE" value=""> <br />
<label>内容概要</label> <textarea style="width:550px;"
	id="ifsummary" name="ifsummary"></textarea> <br/>	
<label>正文内容</label> <input type="hidden" name="ifcontent" value="">
<iframe id="FCKeditor1___Frame"
	src="<%=context%>/resources/fckeditor/editor/fckeditor.html?InstanceName=ifcontent&Toolbar=xfile&uniqueid=<%=uniqueid %>"
	width="100%" height="450" frameborder="0" scrolling="no"></iframe> <br />
</fieldset>
</form>
</body>
</html>
